package com.hyh.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hyh.ad.common.utils.SecurityUtils;
import com.hyh.admin.domain.resources.ResourcesComment;
import com.hyh.admin.mapper.resources.ResourcesCommentMapper;
import com.hyh.admin.service.IResourcesCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;


/*
 *  资源评论-实现类
 */
@Service
public class ResourcesCommentServiceImpl implements IResourcesCommentService {

    @Autowired
    private ResourcesCommentMapper resourcesCommentMapper;


    @Override
    public List<ResourcesComment> selectResourcesComment(ResourcesComment resourcesComment) {
        LambdaQueryWrapper<ResourcesComment> queryWrapper = new LambdaQueryWrapper<>(resourcesComment);
        return resourcesCommentMapper.selectList(queryWrapper);
    }

    @Override
    public int updateResourcesComment(ResourcesComment resourcesComment) {
        return resourcesCommentMapper.updateById(resourcesComment);
    }

    @Override
    public int deleteResourcesComment(ResourcesComment resourcesComment) {
        return resourcesCommentMapper.deleteById(resourcesComment.getId());
    }

    @Override
    public int insertResourcesComment(ResourcesComment resourcesComment) {
        resourcesComment.setUserId(SecurityUtils.getLoginUser().getUser().getId());
        return resourcesCommentMapper.insert(resourcesComment);
    }

    @Override
    public List<ResourcesComment> selectResourcesCommentByUserId(Long userId) {
        LambdaQueryWrapper<ResourcesComment> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ResourcesComment::getUserId, userId);
        return resourcesCommentMapper.selectList(queryWrapper);
    }

    @Override
    public List<ResourcesComment> selectResourcesCommentByParentId(String parentId) {
        LambdaQueryWrapper<ResourcesComment> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ResourcesComment::getParentId, parentId);
        return resourcesCommentMapper.selectList(queryWrapper);
    }

    @Override
    public int deleteResourcesCommentBatch(String[] ids) {
        return resourcesCommentMapper.deleteBatchIds(Collections.singletonList(ids));
    }

    @Override
    public List<ResourcesComment> selectResourcesCommentAll(ResourcesComment resourcesComment) {
        LambdaQueryWrapper<ResourcesComment> queryWrapper = new LambdaQueryWrapper<>(resourcesComment);
        return resourcesCommentMapper.selectList(queryWrapper);
    }
}
